<?php
require 'Doctrine/ORM/Tools/Setup.php';

Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();

use Doctrine\ORM\EntityManager,
    Doctrine\ORM\Configuration;

// ...
$applicationMode = 'development';
if ($applicationMode == "development") {
    $cache = new \Doctrine\Common\Cache\ArrayCache;
} else {
    $cache = new \Doctrine\Common\Cache\ApcCache;
}
//dp not mind this because all you need is to create the db schema based on your entities
$config = new Configuration;
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver('entities');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir('proxies');
$config->setProxyNamespace('testDoctrine\Proxies');

if ($applicationMode == "development") {
    $config->setAutoGenerateProxyClasses(true);
} else {
    $config->setAutoGenerateProxyClasses(false);
}
//connection parameters to database
$connectionOptions = array(
    'driver' => 'pdo_mysql',
   	'user' =>'root',
	'password' => '',
	'host' => 'localhost',
	'dbname' => 'test_claycode'
);
//instance of the entity manager
$em = EntityManager::create($connectionOptions, $config);

//require the entitities created in order to create their db table indexes etc.
require_once "entities/User.php";
require_once 'entities/Article.php';
/*
//auto generate proxies
$cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory($em);
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
$generator = new \Doctrine\ORM\Tools\EntityGenerator();
$generator->setUpdateEntityIfExists(true);
$generator->setGenerateStubMethods(true);
$generator->setGenerateAnnotations(true);
$generator->generate($metadata, 'D:\Dev\php\servers\xampp-test-server\htdocs\custom-sandbox\doctrine-orm-test\proxies');
/* */
//generate the schema or drop it or update
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$classes = array(
	$em->getClassMetadata('User'),
	$em->getClassMetadata('Article')
);
//$tool->createSchema($classes);
//$tool->dropSchema($classes);
$tool->updateSchema($classes);

